﻿namespace System

open System

type Date(day) =
    let dateTime = 
        let year = day / 10000u
        let month = day / 100u
        let month = month % 100u
        let day = day % 100u
        DateTime(int year, int month, int day)
    
    member this.DateTime = dateTime
    member this.Day = day
    
    override this.ToString() =
        day.ToString()
    
    [<OverloadID("date")>]
    member this.CompareTo(other: Date) =
        day.CompareTo(other.Day)
    
    [<OverloadID("datetime")>]
    member this.CompareTo(other: DateTime) =
        dateTime.CompareTo(other)
    
    [<OverloadID("date")>]
    member this.Equals(other: Date) =
        day.Equals(other.Day)
    
    [<OverloadID("datetime")>]
    member this.Equals(other: DateTime) =
        dateTime.Equals(other)
    
    [<OverloadID("object")>]
    override this.Equals(other) =
        match other with
        | :? Date as date ->
            this.Equals(date)
        | :? DateTime as dateTime ->
            this.DateTime.Equals(dateTime)
        | _ -> false
    
    override this.GetHashCode() =
        day.GetHashCode()
    
    interface IEquatable<Date> with
        member this.Equals(other) =
            this.Equals(other)
    
//    interface IEquatable<DateTime> with
//        [<OverloadID("datetime")>]
//        member this.Equals(other) =
//            this.Equals(other)
    
    interface IComparable<Date> with
        member this.CompareTo(other) =
            this.CompareTo(other)
    
//    interface IComparable<DateTime> with
//        [<OverloadID("datetime")>]
//        member this.CompareTo(other) =
//            this.CompareTo(other)
   
    static member Parse input =
        Date(UInt32.Parse input)